package com.yvan.eventsourcing;

import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;

/**
 * Created by Administrator on 2018/12/12.
 */
public class EventTemplateBuilder {

    public static EventTemplate build(EventConfig eventConfig) {
        CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
        connectionFactory.setHost(eventConfig.getRabbitmq().getHost());
        connectionFactory.setPort(eventConfig.getRabbitmq().getPort());
        connectionFactory.setUsername(eventConfig.getRabbitmq().getUsername());
        connectionFactory.setPassword(eventConfig.getRabbitmq().getPassword());
        connectionFactory.setVirtualHost(eventConfig.getRabbitmq().getVhost());

        EventTemplate eventTemplate = new EventTemplate(connectionFactory);
        eventTemplate.setVersion(eventConfig.getVersion());
        return eventTemplate;
    }
}
